package com.xzj.admin.resource.analysis.handle.analysis;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @program: xzj-admin
 * @ClassName: MsgAnalysisHandle
 * @description: 消息解析处理
 * @author: XiaZunJun
 * @create: 2024-11-04 17:03
 */
@Component
@Slf4j
public class MsgAnalysisHandle {

    /**
     * 解析kafka消息数据
     *
     * @param record kafka消息记录
     * @author xiazunjun
     * @date 2023/8/15 17:12
     */
    public void analysisKafkaMsg(ConsumerRecord<String, String> record) {
        try {
            Optional<String> message = Optional.ofNullable(record.value());
            // 判断消息是否存在
            if (message.isPresent()) {
                String msg = message.get();
                JSONObject msgJson = JSONObject.parseObject(msg);
            }
        } catch (Exception e) {
            log.error("analysisKafkaMsg-消息解析异常-{}",JSON.toJSONString(record), e);
        }
    }
}
